package com.jzqf.harmonydemo.ability.slice;

import com.jzqf.harmonydemo.ResourceTable;
import com.jzqf.harmonydemo.base.BaseAbilitySlice;
import com.jzqf.harmonydemo.library.media.MediaPlayer;
import com.jzqf.harmonydemo.utils.LogUtil;
import com.jzqf.harmonydemo.utils.MobileUtil;
import com.jzqf.harmonydemo.utils.NetWorkUtil;
import com.jzqf.harmonydemo.utils.ScreenUtil;
import ohos.aafwk.content.Intent;
import ohos.account.AccountAbility;
import ohos.agp.components.Text;

/**
 * 获取设备信息
 *
 * @author LiuWeiHao
 * 2021/5/20 17:04
 */
public class DeviceInfoAbilitySlice extends BaseAbilitySlice {
    private Text mResultTv;

    @Override
    protected int getLayoutResId() {
        return ResourceTable.Layout_ability_device_info;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setTitle("设备信息");
        mResultTv = (Text) findComponentById(ResourceTable.Id_result_tv);
        findComponentById(ResourceTable.Id_wifi_btn).setClickedListener(component ->
        {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("\nDVID=").append(MobileUtil.getDVID());
            stringBuilder.append("\nssid=").append(NetWorkUtil.getSsid(this));
            stringBuilder.append("\nip=").append(NetWorkUtil.getIp(this));
            setResult(stringBuilder.toString());
        });
        findComponentById(ResourceTable.Id_memory_btn).setClickedListener(component ->
        {
            StringBuffer stringBuilder = new StringBuffer();
            stringBuilder.append("avail=").append(MobileUtil.availMemory(this)).append("M\n");
            stringBuilder.append("total=").append(MobileUtil.totalMemory(this)).append("M\n");
            stringBuilder.append("width=").append(ScreenUtil.getScreenWidth(this)).append("\n");
            stringBuilder.append("height=").append(ScreenUtil.getScreenHeight(this)).append("\n");
            setResult(stringBuilder.toString());
            new MediaPlayer(this).init();
        });
    }


    private void setResult(String text) {
        mResultTv.setText(text);
        LogUtil.d(DeviceInfoAbilitySlice.class.getSimpleName(), text);
    }
}
